package com.dcivision.framework.taglib.channel;


import java.sql.Connection;
import java.util.List;

import javax.servlet.jsp.PageContext;

import org.apache.commons.logging.LogFactory;

import com.dcivision.framework.ApplicationException;
import com.dcivision.framework.GlobalConstant;
import com.dcivision.framework.SessionContainer;

public abstract class AbstractAjaxChannelFormatter {

  protected PageContext pageContext = null;
  protected int pageSize;
  protected List channelList=null;
  protected Connection conn = null;
  protected SessionContainer sessionContainer = null;
  protected int columnCount = 0;
  protected String pattern;//for page INFO
  
  public void init(){
    conn = (Connection)pageContext.getRequest().getAttribute(GlobalConstant.DB_KEY);
    sessionContainer = (SessionContainer)pageContext.getSession().getAttribute(GlobalConstant.SESSION_CONTAINER_KEY);
  }
  public abstract String[] getContent()throws Exception;
  
  /**
   * if want to get different pageIndex format,should reWrite this method
   * @param colspan
   * @return
   * @throws ApplicationException
   */
  protected String[] getPageInfoContent(int colspan) throws ApplicationException{

    try{
      String[] ageStrs = new AjaxPagerFormatter_1().getPageIndexContext(pageContext, pageSize, channelList,pattern);
      return ageStrs;
    }catch(Exception ex){
      LogFactory.getLog(this.getClass()).error(ex.getMessage(), ex);
      throw new ApplicationException(ex);
    }
  }
  protected String[] parsePageInfo(StringBuffer content) throws ApplicationException{
    String[] pageInfo = getPageInfoContent(columnCount);
    String[] contents = new String[3];
    contents[0] = content.toString();
    contents[1] = pageInfo[0];
    contents[2] = pageInfo[1];
    return contents;
  }
}
